#include "randomgenerateclass.h"

#include <QElapsedTimer>
#include <QDebug>

#include <vector>
#include <random>
#include <iostream>

RandomGenerateClass::RandomGenerateClass(QObject* parent) : QThread{ parent }
{
}

void RandomGenerateClass::generateRandom()
{
    QElapsedTimer timer;
    timer.start();
    std::vector<int> list;
    std::random_device seed;                               // 真随机数生成器，得到随机数种子
    std::mt19937 gen(seed());                              // 伪随机数生成引擎
    std::uniform_int_distribution distribution(0, 100000); // 分布器
    for (int i = 0; i < this->randomCount; i++)
    {
        list.push_back(distribution(gen));
    }
    int millisecond = timer.elapsed();
    std::cout << "生成" << this->randomCount << "用时" << millisecond << "毫秒" << std::endl;
    emit sendVector(list);
}

void RandomGenerateClass::setRandomCount(int count)
{
    this->randomCount = count;
}

void RandomGenerateClass::run()
{
    std::cout << "线程地址" << QThread::currentThread() << std::endl;
    this->generateRandom();
}
